﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace PhysicsSimulator.SpringsPendulum
{
    public partial class SpringsPendulumDataPage : PhoneApplicationPage
    {
        public SpringsPendulumDataPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            Settings.SpringsEnviromentRatio = (float)EnviromentRatio.Value;
            Settings.SpringsK = float.Parse(KTextBox.Text);

            Settings.spring_save_active = true;
        }

        private void KSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            float value = 5 + 45 * (float)KSlider.Value / 10;
            KTextBox.Text = value.ToString();
        }

        private void KTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox textbox = sender as TextBox;
            String text = textbox.Text;
            float value = float.Parse(text);
            if (value > 50)
            {
                textbox.Text = "50";
                value = 50;
            }

            KSlider.Value = 10*(value - 5)/45.0f;
        }
    }
}